package com.vincent.jvmtest.stream;

import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
public class StreamTest {
    public static void main(String[] args) {
        List<TransferVo> list = getData();
        Map<String, List<TransferVo>> numbergb = list.stream().collect(Collectors.groupingBy(TransferVo::getNumber));
        System.out.println(numbergb);
        for (Map.Entry<String, List<TransferVo>> entry : numbergb.entrySet()) {
            String number = entry.getKey();
            List<TransferVo> transferVos = entry.getValue();
            Map<String, Long> optCount = transferVos.stream().collect(Collectors.groupingBy(TransferVo::getOption, Collectors.counting()));
            int size = transferVos.size();
            log.info("number:{} > size: {}  opt > {}",
                    number,
                    size,
                    optCount);
        }

        Map<String, List<TransferVo>> namegb = list.stream().collect(Collectors.groupingBy(TransferVo::getName));
        System.out.println(namegb);


    }

    public static List<TransferVo> getData(){
        List<TransferVo> list = new ArrayList<>();
        String id = IdUtil.fastSimpleUUID();
        String number = "1380006666";
        String number1 = "1390009999";
        String number2 = "1370002222";
        String number3 = "1360008888";

        String name = "张三";
        String name2 = "李四";
        String name3 = "王五";

        String opt1 = "xf";
        String opt2 = "fs";
        TransferVo transferVo = TransferVo.builder().id(id).number(number).name(name).option(opt1).build();
        list.add(transferVo);
        list.add(TransferVo.builder().id(id).number(number3).name(name).option(opt1).build());
        list.add(TransferVo.builder().id(id).number(number1).name(name3).option(opt1).build());
        list.add(TransferVo.builder().id(id).number(number2).name(name2).option(opt1).build());

        list.add(TransferVo.builder().id(id).number(number3).name(name).option(opt2).build());
        list.add(TransferVo.builder().id(id).number(number1).name(name3).option(opt2).build());

        return list;
    }
}
